package com.springcloud.util.model;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import static com.springcloud.util.model.NumberUtils.parseNumber;

/**
 * @Description: TODO
 * @Create by: 123
 * @Date: 2021/11/22 16:33
 */

@Data
public class Margins {

    private float marginTop;
    private float marginRight;
    private float marginBottom;
    private float marginLeft;

    public Margins(String margins) {
        parse(margins);
    }

    private void parse(String margins) {
        if (StringUtils.isNotBlank(margins)) {
            margins = margins.replace("[","").replace("]","");
            String[] strings = margins.split(",");
            for (int i = 0; i < Math.min(strings.length, 4); i++) {
                if (i == 0) marginTop = parseNumber(strings[0]);
                if (i == 1) marginRight = parseNumber(strings[1]);
                if (i == 2) marginBottom = parseNumber(strings[2]);
                if (i == 3) marginLeft = parseNumber(strings[3]);
            }
        }
    }
}
